package helper

import (
	"net/mail"
	"regexp"
	"strings"
)

// DesensitizationEmail 将邮箱脱敏
func DesensitizationEmail(email string) string {
	// 判断手机号是否正确
	_, err := mail.ParseAddress(email)
	if err != nil {
		return ""
	}
	sEmail := strings.Split(email, "@")
	return sEmail[0][:1] + "****@" + sEmail[1]
}

// DesensitizationTel 将手机号脱敏
func DesensitizationTel(tel string) string {
	// 15000000000
	// 判断手机号是否正确
	regRuler := "^1[345789]{1}\\d{9}$"
	telRes, _ := regexp.MatchString(regRuler, tel)
	if !telRes {
		return ""
	}
	return tel[:3] + "****" + tel[7:]
}
